<template>
  <el-dialog title="分配权限" :visible.sync="isShow" @close="closeShow" :before-close="handleClose">
    <pre>{{rightslist}}</pre>
    <div slot="footer">
      <el-button @click="closeShow()">取 消</el-button>
      <el-button type="primary" @click="addRoles()">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  //接收父组件传值
  props: ['isShow'],
  data() {
    return {
      // 所有权限的数据
      rightslist: []
    }
  },
  methods: {
    closeShow() {
      this.$emit('setIsShow', false)
    },
    //before-close 仅当用户通过点击关闭图标或遮罩关闭 Dialog 时起效
    handleClose() {
      this.closeShow()
    },
    async loadRights() {
      const { data: res } = await this.$http.get('rights/tree')
      if (res.meta.status === 200) {
        this.rightslist = res.data
      } else {
        this.$message.error(res.meta.msg)
      }
    }
  },
  watch: {
    isShow: function(val) {
      if (val === true) {
        this.loadRights()
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>